#include "kinitializationsettings.h"
#include "QDebug"
KInitializationSettings::KInitializationSettings(QObject *parent)
    : QObject{parent}
{



}

bool KInitializationSettings::checkAndCreateInitializeSETUPDir()
{
    QDir dir("./SETUP");
    if(dir.exists())
        return true;
    dir.cdUp();
    dir.mkdir("./SETUP");
    return false;
}

bool KInitializationSettings::checkAndCreateKCFDirLocationDir()
{
    QDir dir("./KCFDirLocation");
    if(dir.exists())
        return true;
    dir.cdUp();
    dir.mkdir("./KCFDirLocation");
    return false;
}

void KInitializationSettings::checkAndCreateFileToInitializeSettings()
{

    QJsonObject jsonObject;
    jsonObject.insert("KCFDirLocation","./KCFDirLocation");
    QJsonDocument jsonDocument(jsonObject);
    QByteArray byteArray=jsonDocument.toJson();
    QFile file("./SETUP/setup.setup");
    file.open(QIODevice::WriteOnly);
    file.write(byteArray);
    file.close();
}

QByteArray KInitializationSettings::readKCFDirLocationFromJsonObject(QJsonObject jsonObject)
{
    return jsonObject["KCFDirLocation"].toString().toUtf8();
}


QByteArray KInitializationSettings::setupKCFDirLocation()
{
    bool codeEqualZero=true;
    QJsonObject jsonObj=KPJOH.fileOpen(codeEqualZero,"./SETUP/setup.setup");
    if(codeEqualZero)
        return KPJOH.forwardToBackSlash(readKCFDirLocationFromJsonObject(jsonObj));
    return "";
}



